What is Git?

Marie-Hélène Burle

frontlogo

First, we need to answer the question:

What is version control?

Whenever we work on an important document, we know that we should keep key versions

Example:

  • The version of a manuscript that we sent to our supervisor,
  • The revised version after we addressed their comments,
  • The revised version after we addressed reviewer comments,
  • Etc.

Home-made versioning looks something like this:

It is quite messy…

                      from PhD

And inevitably, it leads to this:

from Geek&Poke



Version control systems (vcs) are software that handle versioning effectively



Which vcs should I use?

Several systems have been developed over the years with various functioning

Then came Git…

Git

Git is an open source distributed vcs created in 2005 by Linus Torvalds for the versioning of the Linux kernel during its development

In distributed vcs, the full history of projects lives on everybody’s machine—as opposed to being only stored on a central server as was the case with centralized vcs. This allows for offline work and multiple backups

Git also introduced an extremely powerful and light-weight branching system

As a result, Git has dominated the competition since 2011

Nowadays, it is indeed extremely rare to come across any other version control system



How does Git work?

Git saves the history of a project as a series of snapshots:

The data is stored as blobs, doesn’t create unnecessary copies (unchanged files are referenced from old blobs), and uses excellent compression

These snapshots are identified by commits:

Each commit has a unique hash and contains the following metadata:

  • Author
  • Date and time
  • The hash of parent commit(s)
  • A descriptive message

When you create the 1st commit, a pointer called a branch is created and points to it:

By default, that first branch is called main

Another pointer (HEAD) points to the branch main

HEAD indicates where we are in the project history

As you create more commits the pointers HEAD and main move automatically:

As you create more commits the pointers HEAD and main move automatically:

For simplicity, the diagrams can be simplified this way:



How can these commits be used?

You can revisit old commits by moving HEAD to them:

This will uncompress the corresponding snapshot and you can look at the state of your files at that commit before going back to your branch

You can also print the differences between various commits

You can create multiple branches to explore alternative developments:

HEAD can be moved between branches to explore and create new commits

You can merge branches:

This is a very brief intro: Git is very powerful

            from xkcd.com

But it is now time to get started!

This is a very brief intro: Git is very powerful

               from xkcd.com





Time to get started!